home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr49 / vesa18.zip / VESA_ET5.C < prev    next >
C/C++ Source or Header  |  1995-01-28  |  5KB  |  151 lines

  1. /* VESA package for emx/gcc --- Copyright (c) 1993 by Johannes Martin */
  2. #include <string.h>
  3. #include <sys/hw.h>
  4.  
  5. #define INCL_VIO
  6. #define INCL_DOSPROCESS
  7.  
  8. #include <os2emx.h>
  9. #include <os2thunk.h>
  10.  
  11. #include "vgaports.h"
  12. #include "vesa.h"
  13. #include "vesadll.h"
  14. #include "common.h"
  15.  
  16. static VESAWORD _Modes[] = { 0x003, 0x012, 0x013, 0x101, 0x102, 0x103,
  17.                              0x104, 0x105, 0x200, 0x201, 0x202, 0xFFFF };
  18.  
  19. static struct _ModeInfo _ModeInfos[] =
  20.     { { 0x1, { 0x0f, 0x7, 0x0, 64, 64, 0x0, 0x0,
  21.                OS2VesaSetWindow, OS2VesaGetWindow, 160,
  22.                640, 400, 8, 16, 1, 4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  23.       { 0x3, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  24.                OS2VesaSetWindow, OS2VesaGetWindow, 80,
  25.                640, 480, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  26.       { 0x3, { 0x1b, 0x7, 0x0, 64, 64, 0x0, 0x0,
  27.                OS2VesaSetWindow, OS2VesaGetWindow, 320,
  28.                320, 200, 8,  8, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  29.       { 0xb, { 0x1b, 0x5, 0x3, 64, 64, 0x0, 0x0,
  30.                OS2VesaSetWindow, OS2VesaGetWindow, 640,
  31.                640, 480, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  32.       { 0xb, { 0x1b, 0x5, 0x3, 64, 64, 0x0, 0x0,
  33.                OS2VesaSetWindow, OS2VesaGetWindow, 100,
  34.                800, 600, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  35.       { 0xb, { 0x1b, 0x5, 0x3, 64, 64, 0x0, 0x0,
  36.                OS2VesaSetWindow, OS2VesaGetWindow, 800,
  37.                800, 600, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  38.       { 0xb, { 0x1b, 0x5, 0x3, 64, 64, 0x0, 0x0,
  39.                OS2VesaSetWindow, OS2VesaGetWindow, 128,
  40.                1024, 768, 8, 16, 4, 4, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  41.       { 0xb, { 0x1b, 0x5, 0x3, 64, 64, 0x0, 0x0,
  42.                OS2VesaSetWindow, OS2VesaGetWindow, 1024,
  43.                1024, 768, 8, 16, 1, 8, 1, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 } },
  44.       { 0xab, { 0x1b, 0x5, 0x3, 64, 64, 0x0, 0x0,
  45.                 OS2VesaSetWindow, OS2VesaGetWindow, 1024,
  46.                 512, 768, 8, 16, 1, 16, 1, 6, 0, 1, 5, 10, 5, 5, 5, 0, 1, 15 } },
  47.       { 0xcb, { 0x1b, 0x5, 0x3, 64, 64, 0x0, 0x0,
  48.                 OS2VesaSetWindow, OS2VesaGetWindow, 1024,
  49.                 512, 768, 8, 16, 1, 16, 1, 6, 0, 1, 5, 11, 6, 5, 5, 0, 0, 0 } },
  50.       { 0xeb, { 0x1b, 0x5, 0x3, 64, 64, 0x0, 0x0,
  51.                 OS2VesaSetWindow, OS2VesaGetWindow, 1024,
  52.                 341, 768, 8, 16, 1, 24, 1, 6, 0, 1, 8, 16, 8, 8, 8, 0, 0, 0 } }
  53.     };
  54.  
  55. VESAWORD *Modes             = _Modes;
  56. struct _ModeInfo *ModeInfos = _ModeInfos;
  57.  
  58. VESABOOL Initialize(void)
  59. {
  60.   _portaccess(CRT_I, CRT_D);
  61.   _portaccess(SEG_SELECT, SEG_SELECT);
  62.   _portaccess(IS1_R, IS1_R);
  63.   _portaccess(ATT_IW, ATT_IW);
  64.   _portaccess(0x3c6, 0x3c8);
  65.   return(TRUE);
  66. }
  67.  
  68. VOID ClearUp(void)
  69. {
  70. }
  71.  
  72. VOID *GetPhysBuf(void)
  73. {
  74.   VIOMODEINFO ModeInfo;
  75.   VIOPHYSBUF  PhysBuf;
  76.  
  77.   ModeInfo.cb  = sizeof(ModeInfo);
  78.   VioGetMode(&ModeInfo, 0);
  79.   PhysBuf.pBuf = (PBYTE) ModeInfo.buf_addr;
  80.   PhysBuf.cb   = 0x10000;
  81.   if (VioGetPhysBuf(&PhysBuf, 0) != 0)
  82.     return(NULL);
  83.   else
  84.     return(MAKEP(PhysBuf.asel[0], 0));
  85. }
  86.  
  87. VESABOOL SetMode(VESAWORD mode)
  88. {
  89.   VIOMODEINFO ModeInfo;
  90.  
  91.   if (ModeInfos[mode].fbtype & 0xf0)
  92.     mode = 7;
  93.   ModeInfo.cb     = 12;
  94.   ModeInfo.fbType = ModeInfos[mode].fbtype;
  95.   ModeInfo.color = ModeInfos[mode].Vesa.NumberOfBitsPerPixel;
  96.   ModeInfo.col    = ModeInfos[mode].Vesa.Width  / ModeInfos[mode].Vesa.CharacterWidth;
  97.   ModeInfo.row    = ModeInfos[mode].Vesa.Height / ModeInfos[mode].Vesa.CharacterHeight;
  98.   ModeInfo.hres   = ModeInfos[mode].Vesa.Width;
  99.   ModeInfo.vres   = ModeInfos[mode].Vesa.Height;
  100.   return(VioSetMode(&ModeInfo, 0) == 0);
  101. }
  102.  
  103. void SetSpecial(VESAWORD mode)
  104. {
  105.   /* disable video */
  106.   _inp8(IS1_R);
  107.   _outp8(ATT_IW, 0x00);
  108.  
  109.   /* (re)set hicolor */
  110.  
  111.   _inp8(0x3c8);
  112.   _inp8(0x3c6);
  113.   _inp8(0x3c6);
  114.   _inp8(0x3c6);
  115.   _inp8(0x3c6);
  116.   _outp8(0x3c6, ModeInfos[mode].fbtype & 0xf0);
  117.   _inp8(0x3c8);
  118.  
  119.   if (ModeInfos[mode].fbtype & 0xf0)
  120.     {
  121.       /* Word Mode, etc */
  122.  
  123.       _outp8(CRT_I, 0x14);
  124.       _outp8(CRT_D, 0x60);
  125.  
  126.       _outp8(CRT_I, 0x17);
  127.       _outp8(CRT_D, 0xab);
  128.     }
  129.   /* enable video */
  130.   _inp8(IS1_R);
  131.   _outp8(ATT_IW, 0x20);
  132. }
  133.  
  134. VESABOOL OS2VesaSetWindow(VESACHAR Window, VESAWORD Address)
  135. {
  136.   if (Window == 0)
  137.     _outp8(SEG_SELECT, (_inp8(SEG_SELECT) & 0xF0) | Address);
  138.   else
  139.     _outp8(SEG_SELECT, (_inp8(SEG_SELECT) & 0x0F) | (Address << 4));
  140.   return(TRUE);
  141. }
  142.  
  143. VESABOOL OS2VesaGetWindow(VESACHAR Window, PVESAWORD Address)
  144. {
  145.   if (Window == 0)
  146.     *Address = _inp8(SEG_SELECT) & 0x0F;
  147.   else
  148.     *Address = _inp8(SEG_SELECT) >> 4;
  149.   return(TRUE);
  150. }
  151.